
function expandFor(n, max_level)
    global seq J index PIE; % global defines in main function
    level = J + 1 - max_level;
    if level > J
        PIE(index, 1) = seq(1) - 1;
        PIE(index, J) = n + 1 - seq(J-1);
        for jj=2:J-1
            PIE(index, jj) = seq(jj) - seq(jj-1); 
            index = index + 1;
        end
        
    else
        start = 1;
        if level > 1
            start = seq(level-1);
        end
        
        for i=start:n+1
            seq(level) = i;
            expandFor(n, max_level-1);
    end

    end 
end
